﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;


namespace Mads.WcfService
{
  
  class Program
  {
    static void Main(string[] args)
    {
      Uri baseAddr = new Uri("http://127.0.0.1:8000/MadsService");
      ServiceHost localHost = new ServiceHost(new TrainManager(), baseAddr);
      TicketsGenerator ticketsGenerator = new TicketsGenerator();
      try
      {
        localHost.AddServiceEndpoint(typeof(ITrainManager), new WSHttpBinding(), "TrainService");

        ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
        smb.HttpGetEnabled = true;
        localHost.Description.Behaviors.Add(smb);

        localHost.Open();
        Console.WriteLine("Service initialized.");
        Console.WriteLine("Press the ENTER key to terminate service.");
        Console.WriteLine();
        Console.ReadLine();

        localHost.Close();
      }
      catch (CommunicationException ex)
      {
        Console.WriteLine("Oops! Exception: {0}", ex.Message);
        Console.ReadLine();
        localHost.Abort();
      }
      TrainBaseConnector.Instance.Dispose();
    }
  }
}
